package arcane.network;

import ggn.server.Server;

import java.io.File;
import java.io.IOException;

public class ArcaneServer extends Server {
	public static final int DEFAULT_PORT = 4900;

	File userInfo;

	// Been assigned ports 4900-4999
	public ArcaneServer(int port) throws IOException {
		super(port);
		this.setIOHandler(new ArcaneIOHandler(this));
		ArcaneServer.DEBUG=true;
		userInfo = new File("userInfo.dat");
		userInfo.createNewFile();
		loadUsers(userInfo);
	}

	/*
	 * Load XML file containing all user's names and passwords (And additional
	 * preference data
	 */
	private void loadUsers(File file) {
		try {
			// TODO load user file via jixb
		} catch (Exception e) {

		}
	}

	public static void main(String[] args) {
		int port = DEFAULT_PORT;
		if (args.length > 1) {
			try {
				port = Integer.parseInt(args[0]);
			} catch (NumberFormatException e) {
				System.err.println("Must specify numeric port value for 1st argument \nUsage - [portNumber]");
				System.exit(1);
			}
		}
		try{
			System.out.println("Initializing server, port = "+port);
			ArcaneServer server = new ArcaneServer(port);
		}catch(IOException e){
			e.printStackTrace();
			System.exit(1);
		}
	}
}